package com.cn.stepLock.chain;

import com.cn.stepLock.enums.ExecuteStatus;
import com.cn.stepLock.exception.ThrowBackException;

import java.util.List;

/**
 * @author Aaron
 * @desc
 * @createTime 2022-02-24 3:15
 * @since
 */
public class ExceptionChain extends TailChain {

    @Override
    public void executeTask(Task task) {
        Throwable throwable = task.throwable;
        Task executeTask = task;
        while (executeTask!=null){
            executeTask.throwable=throwable;
            executeTask = executeTask.preChainTask;
        }
//        List<Task> presentTaskList = getPresentTaskList(task);
//        presentTaskList.forEach(x->{x.throwable=task.throwable;x.status= ExecuteStatus.EXTCUTEING.getValue();});
//        unparkPresentThreadList(task, presentTaskList);
        throw new ThrowBackException(task.throwable.getMessage());
    }

    private boolean isFirstChain(Task task){
        return task.chain.preChain==null;
    }
}
